package com.game.common.utils.pdf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

@Slf4j
public class Test {

    public static void main(String[] args) throws IOException {
        long startTime = System.currentTimeMillis();
        //       html文件所在相对路径
        //       pdf文件存储相对路径
        String pdfFile = "D:\\x6.pdf";
        //        自定义水印
        String waterMarkText =  "张三-17736839393";
        OutputStream outputStream = new FileOutputStream(pdfFile);
        //微软雅黑在windows系统里的位置如下，linux系统直接拷贝该文件放在linux目录下即可
        //        String fontPath = "src/main/resources/font/STHeiti Light.ttc,0";
        String html = "<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "\n" +
                "<head>\n" +
                "\t<meta charset=\"UTF-8\">\n" +
                "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n" +
                "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
                "\t<title>Document</title>\n" +
                "</head>\n" +
                "\n" +
                "<body>\n" +
                "\t<div>\n" +
                "\t\t<table class=\"table\" cellpadding=\"10px\" style=\"border: 1px solid #46BCA3;width: 1100px;border-collapse: collapse;\">\n" +
                "\t\t\t<caption style=\"font-weight: 700;margin: 10px 0;\">申请单详细信息</caption>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请单号:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\"><img src=\"\"/></td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请时间:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">2019-11-1110:18:29</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请标题:</td>\n" +
                "\t\t\t\t<td colspan=\"3\" style=\"border: 1px solid #46BCA3\">光口</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请人:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">吴俊杰</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请类型:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">城域网资源申请</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请单状态:</td>\n" +
                "\t\t\t\t<td colspan=\"3\" style=\"border: 1px solid #46BCA3\">资源分配完成</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">是否预留资源:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">是</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">预留截止时间:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">2021-12-23 16:34:17</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">承载业务类型:</td>\n" +
                "\t\t\t\t<td colspan=\"3\" style=\"border: 1px solid #46BCA3\">olt</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">承载OLT名称:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">武侯(81#)祥和街73号-OLTO11</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">OLT规划IP地址:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">10.41.189.5</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">申请人备注:</td>\n" +
                "\t\t\t\t<td colspan=\"3\" style=\"border: 1px solid #46BCA3\">宋俊霖</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">调度备注:</td>\n" +
                "\t\t\t\t<td colspan=\"3\" style=\"border: 1px solid #46BCA3\">ok</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">最近修改人:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">吴俊杰</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">最近修改时间:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">2021-12-23102429</td>\n" +
                "\t\t\t</tr>\n" +
                "\n" +
                "\t\t</table>\n" +
                "\t\t<table class=\"table\" cellpadding=\"10px\" style=\"border: 1px solid #46BCA3;width: 1100px;border-collapse: collapse;\">\n" +
                "\t\t\t<caption style=\"font-weight: 700;margin: 10px 0;\">城域网资源</caption>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">设备IP地址:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">221.182.42.22</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">设备名称</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">21</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">接口类型:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">光口</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">接口带宽:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">10G</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">接口用途:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">专线</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">预占用描述:</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">武侯(81#)祥和街73号-OLT011</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td>申请数量:</td>\n" +
                "\t\t\t\t<td colspan=\"3\">2</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t</table>\n" +
                "\t\t<table class=\"table\" cellpadding=\"10px\" style=\"border: 1px solid #46BCA3;width: 1100px;border-collapse: collapse;\">\n" +
                "\t\t\t<caption style=\"font-weight: 700;margin: 10px 0;\">分配的城域网资源</caption>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<th style=\"border: 1px solid #46BCA3\">接口名称</th>\n" +
                "\t\t\t\t<th style=\"border: 1px solid #46BCA3\">使用情况</th>\n" +
                "\t\t\t\t<th style=\"border: 1px solid #46BCA3\">槽位</th>\n" +
                "\t\t\t\t<th style=\"border: 1px solid #46BCA3\">接口带宽</th>\n" +
                "\t\t\t\t<th style=\"border: 1px solid #46BCA3\">接口类型</th>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">GigabitEthernet7/0/1</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">已使用[预占用]</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">7</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">10G</td>\n" +
                "\t\t\t\t<td style=\"border: 1px solid #46BCA3\">光口</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t</table>\n" +
                "\t</div>\n" +
                "</body>\n" +
                "\n" +
                "</html>";
        System.out.println(ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "template/font/simsun.ttf"));
        HtmlToPdfUtils.convertToPdf(html, null, outputStream);
        log.info("转换结束，耗时：{}ms",System.currentTimeMillis()-startTime);
    }
}
